package com.example.demodb.controller;

import com.example.demodb.entity.UserSong;
import com.example.demodb.service.UserSongService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserSongController {
    @Resource
    private UserSongService userSongService;
    @GetMapping("/UserSongController/findAll")
    @CrossOrigin
    public List<UserSong> findAll(){
        return userSongService.findAll();
    }

    @GetMapping("/UserSongController/deleteById/{id}")
    @CrossOrigin
    public void delete(@PathVariable Long id){
        userSongService.delete(id);
    }


    //借口原名为UserSongController/saveUserSong, 将检查用户是否存在,新增用户的功能放到一起
    //如果这里不分开写的话,也合理,因为check的返回值就可以定义成int了,这样子就不会出现空对象前端无法识别的问题
    @PostMapping("/UserSongController/add") //RO表示该接口 会返回一个对象
    @CrossOrigin
    public UserSong add(@RequestBody UserSong userSong){
        return userSongService.add(userSong);//返回为空的话,就说明为0
    }

    @PostMapping("/UserSongController/update") //RO表示该接口 会返回一个对象
    @CrossOrigin
    public void update(@RequestBody UserSong userSong){
        userSongService.update(userSong);//返回为空的话,就说明为0
    }
}
